import request from '@/utils/request'
import { defineStore } from 'pinia'
import { ApiRes, BannerItem, homeNewItem,homeNotItem } from '@/types/data'
export default defineStore('home', {
  state () {
    return {
      bannerList: [] as BannerItem[],
      homeNewsList:[] as homeNewItem[],
      homeNotList:[] as homeNotItem[]
    }
  },
  actions: {
    async homeBanner () {
      const res = await request.request<ApiRes<BannerItem[]>>({
        url: '/home/banner'
      })
      this.bannerList = res.data.result
      // console.log('轮播图数据', res)
    },
    async homeNew(){
      const res = await request.request<ApiRes<homeNewItem[]>>({
        url: '/home/new'
      })
      this.homeNewsList= res.data.result
      //console.log('新鲜好物',res);
      
    },
    async homeHot(){
      const res = await request.request<ApiRes<homeNotItem[]>>({
        url: '/home/hot'
      })
      this.homeNotList = res.data.result
      // console.log('人气推荐',res);
      
    }
  }
})
